<?php

class Scoring_Controller extends Template_Controller {
    public function __construct(){
        $this->need_template = false;
        if (in_array(Router::$method, array ('index')) ) {
            $this->need_template = true;
        }

        parent::__construct();
    }

    public function index($competition_id = null){
        $this->title = "Scoring";

        $competition = null;

        if ($competition_id == null) {
            $competition = ORM::factory('competition')->get_last_competition();
        } else {
            $competition = ORM::factory('competition', $competition_id);
        }

        $users = $competition->users;
        $this->content->users = array();

        $i = 1;
        foreach ($users as $user) {
            /// TODO : sort user by gross
            $this->content->users[$i]["name"]   = $user->name;
            $this->content->users[$i]["1st"]    = 0;
            $this->content->users[$i]["2nd"]    = 0;
            $this->content->users[$i]["gross"]  = $this->content->users[$i]["1st"] + $this->content->users[$i]["2nd"];
            $this->content->users[$i]["hcap"]   = $user->hcap;
            $this->content->users[$i]["nett"]   = $this->content->users[$i]["gross"] - $user->hcap;

            ++$i;
        }
    }
}
?>
